#!/usr/bin/python -S
"""
lexer_test.py: Tests for lexer.py
"""

import unittest

import annex


class LexerTest(unittest.TestCase):

  def setUp(self):
    pass

  def tearDown(self):
    pass

  def testLexer(self):
    # Using CRE syntax
    l = annex.Lexer({
      'start': [
        ('&space+', lambda m, c: ('space', m.group(0))),
        ('digit+', lambda m, c: ('num', m.group(0))),
        ]
      })
    t = list(l.lex('1 23 456'))
    print t

  def testReLexer(self):
    # Using CRE syntax
    l = annex.Lexer({
      'start': [
        (r'\s+', lambda m, c: ('space', m.group(0))),
        (r'\d+', lambda m, c: ('num', m.group(0))),
        ]
      }, use_re=True)
    t = list(l.lex('1 23 456'))
    print t

  def testParseErrors(self):
    """Test what happens when an invalid expression is passed."""
    lex = annex.Lexer({})
    print lex


if __name__ == '__main__':
  unittest.main()
